package com.zhl.ip1;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class InetAddressTest1 {
    public static void main(String[] args) throws Exception {
        //获取本机的Ip地址和对象
        InetAddress ip1 = InetAddress.getLocalHost();
        System.out.println(ip1.getHostName());
        System.out.println(ip1.getHostAddress());

        //获取指定域名的Ip地址和对象
        InetAddress ip2 = InetAddress.getByName("www.baidu.com");
        System.out.println(ip2.getHostName());
        System.out.println(ip2.getHostAddress());
    }
}
